package com.sdry.web.controller.workplace;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sdry.model.workplace.Assemble;
import com.sdry.model.workplace.AssembleExample;
import com.sdry.model.workplace.MousseBundleSample;
import com.sdry.model.workplace.MousseSample;
import com.sdry.model.workplace.MousseSampleExample;
import com.sdry.model.workplace.MousseSampleExample.Criteria;
import com.sdry.service.workplace.AssembleServise;
import com.sdry.service.workplace.CentrifugalServise;
import com.sdry.service.workplace.MousseBundleSampleServise;
import com.sdry.service.workplace.MousseSampleServise;
import com.sdry.utils.ResponseUtil;

/**
 * @ClassName: OthersController
 * @Description: 生产工位相关
 * @author tdd
 * @date 2018年8月29日
 * @version V1.0
 */
@Controller
@RequestMapping("/revoke")
public class MousseBundleSampleRevokeController {
	//组装
	@Resource
    private AssembleServise assembleServise;
	//离心机
	@Resource
    private CentrifugalServise centrifugalServise;
	//膜丝
	@Resource
    private MousseBundleSampleServise mousseBundleSampleServise;
	//膜丝绑定
	@Resource
	private MousseSampleServise mousseSampleServise;

	 /**
	  * 膜丝
	  * @param response
	  * @param mousseBundleSample
	  * @throws Exception
	  */
    @RequestMapping("/mousseBundleSample")
    public void mousseBundleSample(HttpServletResponse response,MousseBundleSample mousseBundleSample) throws Exception {
    	//返回标识   0 失败   -1 已经在下一工位  -2已经删除   1成功    -3 膜丝绑定
        int affact = 0;
        MousseBundleSample mousseBundleSamples = mousseBundleSampleServise.selectByPrimaryKey(mousseBundleSample.getMbsid());
        if(mousseBundleSamples != null){
        	 MousseSampleExample mousseSample = new MousseSampleExample();
             Criteria createCriteria = mousseSample.createCriteria();
             createCriteria.andMbcodeEqualTo(String.valueOf(mousseBundleSample.getMbsid()));
             List<MousseSample> mousseSamples = mousseSampleServise.selectByExample(mousseSample);
             
             
             AssembleExample example = new AssembleExample();
             com.sdry.model.workplace.AssembleExample.Criteria createCriteria2 = example.createCriteria();
             createCriteria2.andAtubeEqualTo(String.valueOf(mousseBundleSample.getMbsid()));
             createCriteria2.andAremarkEqualTo("0");
             List<Assemble> assembles = assembleServise.selectByExample(example);
             
             if(mousseSamples.size() > 0 || assembles.size() > 0){
            	 affact = -1;
             }else{
            	 int aff = mousseBundleSampleServise.deleteByPrimaryKeys(String.valueOf(mousseBundleSample.getMbsid()));
            	 if(aff > 0 ){
            		 affact = 1;
            	 }
             }
             
        }else{
        	affact = -2;
        }
        ResponseUtil.write(response, affact);
    }

}
